package com.mycompany.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.mycompany.dao.InvoiceDao;
import com.mycompany.model.Invoice;

@Repository("invoiceDao")
public class InvoiceDaoHibernate extends GenericDaoHibernate<Invoice, Long> implements InvoiceDao {

	public InvoiceDaoHibernate() {
		super(Invoice.class);
	}
	
	public InvoiceDaoHibernate(Class<Invoice> persistentClass) {
		super(persistentClass);
		// TODO Auto-generated constructor stub
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Invoice> getInvoices(int page, int pageSize) {
		String hql = "from Invoice"; 
	
		List<Invoice> invoices = 
		    getHibernateTemplate().executeFind(
		        new HibernateCallbackImpl(
		            hql, 
		            null, 
		            null,
		            (page-1)*pageSize,
		            pageSize
		        )
		    );

		return invoices;
	}

	@Override
	public Invoice getInvoice(Long id) {		
		return getHibernateTemplate().get(Invoice.class, id);
	}

	
}
